package com.zzl.mine.service.oss.impl;

import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.zzl.mine.resolver.ImgException;
import com.zzl.mine.service.oss.OSSService;
import com.zzl.mine.tool.OSSClientUtil;

/**
 * @description 阿里云OSS服务接口实现类
 * @author rambo
 * @date 2018年12月15日 下午1:45:02
 */
@Service
public class OSSServiceImpl implements OSSService {
	
	private static String endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
	private static String accessKeyId = "LTAIgGMrJS06Femx";
    private static String accessKeySecret = "GK4c1PLxGTeNZz6KAp4MhYp6OjQkCi";
    private static String bucketName = "xxssxbbucket";
    private static String projectName = "education";
    private static String modelName = "videoInfo";
	
	/**
	 * @description 上传文件
	 * @param file 文件对象
	 * @return 返回访问url地址
	 */
	@Override
	public String uploadImg(MultipartFile file) {
		if (file == null || file.getSize() <= 0) {
			throw new ImgException("文件不能为空");
		}
		String imgUrl = "";
		try {
			imgUrl = OSSClientUtil.uploadFile(file, endpoint, accessKeyId, accessKeySecret, bucketName, projectName, modelName);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return imgUrl;
	}

}
